package com.tuangou.tuangouheader.header.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.tuangou.tuangouheader.header.dao.GroupGoodsDao;
import com.tuangou.tuangouheader.header.entity.GroupGoodsEntity;
import com.tuangou.tuangouheader.header.service.GroupGoodsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tuangou.tuangouheader.header.entity.vo.TbGroupGoodsEntityVo;

import java.util.List;
import java.util.Map;


@Service("groupGoodsService")
public class GroupGoodsServiceImpl extends ServiceImpl<GroupGoodsDao, GroupGoodsEntity> implements GroupGoodsService {
    @Autowired
    private GroupGoodsDao groupGoodsDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GroupGoodsEntity> page = this.page(
                new Query<GroupGoodsEntity>().getPage(params),
                new QueryWrapper<GroupGoodsEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public GroupGoodsEntity findGroupGoods(Integer goodsId) {
        GroupGoodsEntity groupGoodsEntity = groupGoodsDao.findGroupGoods(goodsId);
        return groupGoodsEntity;
    }

    @Override
    public PageInfo<TbGroupGoodsEntityVo> findAll(int status, String mohu, int cpage) {
        PageHelper.startPage(cpage,3);
        List<TbGroupGoodsEntityVo> list = groupGoodsDao.findAll(status,mohu);
        PageInfo<TbGroupGoodsEntityVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}